<template>
  <div>
    <img :src="$pre + info.img" alt="" />
    <div>name:{{ info.goodsname }}</div>
    <div>price:{{ info.price }}</div>
    <!-- <div>数量：<button @click="n--">-</button><span>{{n}}</span><button @click="n++">+</button></div> -->
    <!-- <button @click="mai">加入购物车</button>
    <button @click="$router.push('/index/shop')">购物车</button>
    <button>立即购买</button> -->
    <van-goods-action>
      <van-goods-action-icon icon="chat-o" text="客服" dot />
      <van-goods-action-icon icon="cart-o" text="购物车"  @click="$router.push('/index/shop')"  />
      <van-goods-action-icon icon="shop-o" text="店铺" />
      <van-goods-action-button type="warning" text="加入购物车" @click="mai" />
      <van-goods-action-button type="danger" text="立即购买" />
    </van-goods-action>
  </div>
</template>

<script>
import { reqdetail } from "../../http/http";

import { reqcartadd } from "../../http/http";
import { Toast } from 'vant';
export default {
  data() {
    return {
      info: {},
    };
  },
  mounted() {
    reqdetail({
      id: this.$route.params.id,
    }).then((res) => {
      this.info = res.data.list[0];
      this.info.specsattr = this.info.specsattr.split(",");
    });
  },
  methods: {
    mai() {
    
      reqcartadd({
        uid: JSON.parse(localStorage.getItem("isLogin")).uid,
        goodsid: this.info.id,
        num: 1,
      }).then((res) => {
        console.log(res);
        if (res.data.code == 200) {
          Toast("加入购物车成功");
        }
      });
    },
  },
};
</script>
<style scoped>
img {
  width: 100%;
  height: 100%;
}
</style>